

<template>
  <!-- 积分商城 -->
  <view class="Mall4j integral-index">
    <view class="integral-msg">
      <image src="/package-member-integralhttps://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/integral-bg.png" class="bg" />
      <view class="my-integral">
        <view class="number-box">
          <view class="text">{{ i18n.myIntegral }}</view>
          <view class="number">{{ scoreInfo.score }}</view>
        </view>
        <view class="det" data-path="scoreDet" @tap="navigateTo">{{ i18n.detailed }}
          <image src="/package-member-integralhttps://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/white-arr.png" />
        </view>
      </view>
      <view class="make" data-path="scoreIndex" @tap="navigateTo">
        <image src="/package-member-integralhttps://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/make-integral.png" />{{ i18n.earnPoints }}
      </view>
    </view>
    <view class="integral-list">
      <view class="member-tit">
        <view class="text">{{ i18n.pointsExchange }}</view>
      </view>
      <view class="con-box">
        <!-- <view class="item" wx:for="{{scoreProdList}}" wx:key="prodId" wx:for-item="prod" bindtap="toScoreProdDet" data-scoreprodid="{{prod.prodId}}">
        <view class="img">
          <image src="{{prod.pic}}" />
        </view>
        <view class="name">{{prod.prodName}}</view>
        <view class="price">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/integral-icon.png" class="icon" />
          {{prod.scorePrice}}积分+{{prod.price}}元
        </view>
        <view class="old-price">市场价￥{{prod.oriPrice}}</view>
      </view> -->
        <block v-for="(prod, prodId) in scoreProdList" :key="prodId">
          <goodsitem :prod="prod" />
        </block>
      </view>
      <!-- 空 -->
      <empty v-if="scoreProdList.length==0" />
    </view>
  </view>
</template>

<script>
// pages/integral-index/integral-index.js
var http = require('@/utils/http.js')
import goodsitem from '../../components/lntegral-goods-list/index.vue'
import empty from '@/components/empty-tips/index.vue'

export default {

  components: {
    goodsitem,
    empty
  },
  data () {
    return {
      current: 1,
      scoreProdList: [],
      scoreInfo: '',
      pages: ''
    }
  },

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getScoreProdList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 设置头部导航标题
    uni.setNavigationBarTitle({
      title: this.i18n.pointsMall
    })
    // 获取当前积分信息
    this.getScoreInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.current < this.pages) {
      this.current = this.current + 1
      this.getScoreProdList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { },
  methods: {
    /**
     * 跳转
     */
    navigateTo (e) {
      const path = e.currentTarget.dataset.path

      if (path == 'scoreDet') {
        uni.navigateTo({
          url: '/package-member-integral/pages/integral-detail/integral-detail'
        })
      } else if (path == 'scoreIndex') {
        uni.navigateTo({
          url: '/package-member-integral/pages/member-index/member-index'
        })
      }
    },

    /**
     * 获取当前积分信息
     */
    getScoreInfo () {
      var params = {
        url: '/p/score/scoreInfo',
        method: 'GET',
        data: {},
        callBack: res => {
          this.setData({
            scoreInfo: res
          })
        }
      }
      http.request(params)
    },

    /**
     * 获取积分商品列表
     */
    getScoreProdList () {
      var param = {
        url: '/p/score/prodScorePage',
        method: 'GET',
        data: {
          current: this.current,
          size: 10
        },
        callBack: res => {
          uni.hideLoading()
          var scoreProdList = []

          if (this.current == 1) {
            this.setData({
              scoreProdList: res.records,
              pages: res.pages,
              current: res.current
            })
          } else {
            scoreProdList = this.scoreProdList
            scoreProdList.push(...res.records)
            this.setData({
              scoreProdList,
              pages: res.pages,
              current: res.current
            })
          }
        }
      }
      http.request(param)
    }
  }
}
</script>
<style>
@import "./integral-index.css";
</style>
